package com.zjgsu.demo.controller;

import com.zjgsu.demo.Repository.DevRepository;
import com.zjgsu.demo.nodeEntity.Dev;
import com.zjgsu.demo.result.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/rest/v1.0/database/dev")
public class DevController {
    @Autowired
    DevRepository devRepository;
    //存储实体
    @PostMapping("/save")
    public ResponseResult createDevice(@RequestBody Dev device) throws Exception{

        Dev result = devRepository.save(device);
        if(result!=null){
            return new ResponseResult(200,result.getDevName()+"节点创建成功！");
        }
        return new ResponseResult(500, device.getDevName()+"节点创建失败！");
    }
    //获取全部实体
    @PostMapping("/all")
    public Iterable<Dev> all() throws Exception{
        Iterable<Dev> devices = devRepository.findAll();
        return devices;
    }
}
